﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Helper;

namespace NJGZBTYHXT
{
    public partial class SetSkinForm : Form
    {
        public SetSkinForm()
        {
            InitializeComponent();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            object v = listBox1.Items[listBox1.SelectedIndex];

            if (v != null)
            {
                this._skinName = v;
                XmlHelper.UpdataNodeValue(Application.ExecutablePath + ".config", "/configuration/appSettings/add[@key='skinName']", v);
                MessageBox.Show("主题设置完成", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                MessageBox.Show("没有选择主题", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void SetSkinForm_Load(object sender, EventArgs e)
        {
            string skinDir = Application.StartupPath + @"\Skins";

            if (Directory.Exists(skinDir))
            {
                string[] files = Directory.GetFiles(skinDir, "*.ssk", SearchOption.TopDirectoryOnly);

                if (files.Length > 0)
                {
                    listBox1.Items.Clear();

                    foreach (string filename in files)
                    {
                        listBox1.Items.Add(Path.GetFileNameWithoutExtension(filename));
                    }
                }
            }
            else
            {
                MessageBox.Show("Skins 目录不存在", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private object _skinName;
        public object SkinName { get { return _skinName; } set { _skinName = value; } }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Form1 form1 = this.Owner as Form1;
            object v = listBox1.Items[listBox1.SelectedIndex];
            this._skinName = v;
            form1.LoadSkin(v);
        }
    }
}
